package com.dlnu.sujiwords.controller;

import com.dlnu.sujiwords.domain.client.AjaxResult;
import com.dlnu.sujiwords.domain.client.UpdateLearnVocabularyParameter;
import com.dlnu.sujiwords.domain.pojo.User;
import com.dlnu.sujiwords.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@CrossOrigin
@RequestMapping("/SuJiWords/user")
public class UserController {
    @Resource
    private IUserService iuserService;
    @RequestMapping("/login")
    @ResponseBody
    public AjaxResult login(@RequestBody User loginuser){
        System.out.println(loginuser.getPhone_number()+loginuser.getPassword()+"");
        return iuserService.login(loginuser);
    }
    @PostMapping("/sign")
    @ResponseBody
    public AjaxResult sign(@RequestBody User signuser){
        return iuserService.normalSign(signuser);
    }

    @GetMapping("/selAll")
    @ResponseBody
    public AjaxResult selAllUser(){
        return iuserService.selAllUser();
    }
    @GetMapping("/selOnline")
    @ResponseBody
    public AjaxResult selOnline(){
        return iuserService.selOnlineUser();
    }
    /*创建新用户*/
    @RequestMapping("/createUser")
    @ResponseBody
    public AjaxResult creUser(@RequestBody User create){
        System.out.println(create);
        return iuserService.createUser(create);
    }
    @RequestMapping("/updateUser")
    @ResponseBody
    public AjaxResult updUser(@RequestBody User update){
        return iuserService.updateUser(update);
    }
    @DeleteMapping("/delUser/{delId}")
    public AjaxResult delUser(@PathVariable("delId") int delId){
        return iuserService.delUserByid(delId);
    }

    @GetMapping("/findUser/{phoneNumber}")
    public AjaxResult findUser(@PathVariable("phoneNumber")String pho){ return  iuserService.selUserByPho(pho);}

    @GetMapping("/getLearn_vocabulary/{phoneNumber}")
    public AjaxResult getLearnVocabulary(@PathVariable("phoneNumber")String pho){
        return iuserService.selUserLearnVocabulary(pho);
    }
    @RequestMapping("/updateLearn_vocabulary")
    public AjaxResult updateLearnVocabulary(@RequestBody UpdateLearnVocabularyParameter parameter){
        System.out.println(parameter);
        return iuserService.updateLearnVocabulary(parameter.getPhoneNumber(),parameter.getVocabularyType());
    }

}
